



# d ; 


*label variables to mathc the names in the tables ;
label var exp_L_IH_SF12a_r "\(I^{L}_{st} \)";
label var  exp_IRI_IH_SF12a_r "\( Y^L\:in\:IRI \)";
label var  exp_IH_mtn_SF12a_r "\( Y^L\: in\: Maint.\)";


*make lagged expenditure and appropriations;
sort state year;
gen L1exp_L_IH_SF12a_r=cond(
			state[_n]==year[_n-1],
			year[_n-1]==year[_n]-1,
			exp_L_IH_SF12a_r[_n-1],.);
gen L5app_IH_r=cond(
			state[_n]==year[_n-5],
			year[_n-5]==year[_n]-5,
			app_IH_r[_n-5],.);

			
gen L1app_IH_r=cond(
			state[_n]==year[_n-1],
			year[_n-1]==year[_n]-1,
			app_IH_r[_n-1],.);			
			


			
*calculate first differences in miles and IRI;
*local D_vars "u_iri_IH u_iri_urban u_iri_rural u_lane_miles_IH u_lane_miles_rural u_lane_miles_urban";
local D_vars u_lane_miles_IH  u_lane_miles_rural u_lane_miles_urban u_miles_IH;
sort state year;
foreach varname of local D_vars{;
		gen D`varname'=cond(
				state[_n]==state[_n-1]&
				`varname'[_n-1]!=.&`varname'[_n]!=.&
				`varname'[_n-1]!=0&`varname'[_n]!=0&
				year[_n-1]==year[_n]-1,
				`varname'[_n]-`varname'[_n-1],.);
				};
				

*Create average width of lane miles ;
gen u_width_IH= u_lane_miles_IH/u_miles_IH;
label var u_width_IH "Avergae width of lanes";
				
*create expantion lanes in existing segments and new segments; 				
gen Du_expantion_miles_IH=cond(
				state[_n]==state[_n-1]&
				u_lane_miles_IH[_n-1]!=.&u_lane_miles_IH[_n]!=.&
				u_miles_IH[_n-1]!=.&u_miles_IH[_n]!=.&
				year[_n-1]==year[_n]-1,
				Du_lane_miles_IH - Du_miles_IH*u_width_IH[_n-1],
				.);
*replace Du_expantion_miles_IH=0 if Du_expantion_miles_IH<0;			
label var Du_expantion_miles_IH "Expansion miles"; 				
//note: The assumption to create this variable is that the new miles occurs at mean width ;

gen sh_new_lm=cond(state[_n]==state[_n-1]&
				u_lane_miles_IH[_n-1]!=.&u_lane_miles_IH[_n]!=.&
				u_miles_IH[_n-1]!=.&u_miles_IH[_n]!=.&
				year[_n-1]==year[_n]-1, Du_miles_IH*u_width_IH/Du_lane_miles_IH,.) ;

*replace sh_new_lm=1 if Du_expantion_miles_IH==0 & Du_lane_miles_IH>0;
label var sh_new_lm "Share of new lane miles in new segments";
gen sh_exp_lm= Du_expantion_miles_IH/Du_lane_miles_IH;
label var sh_exp_lm "Share of new lane miles that are expantions";


*dropping missing d_lane_miles saves trouble later;
* keep all years with lagge appropriations;
* N.B.: Nothing strange here.  SF12a missing <1984;
drop if year>2008|year<1980;
drop if u_lane_miles_IH==.;
drop if u_lane_miles_IH==0;
drop if u_lane_miles_IH<0;
*drop DC;
drop if state==11;

* time, for estimating trends;
gen time =year-1984;
gen time2 =time^2;
gen time3 =time^3;
label var time2 "\(time^2\)" ;
label var time3 "\(time^3\)" ;
*TIME TREND DUMMIES;

gen     periods=1 if  year>=1984&year<=1989;
replace periods=2 if  year>=1990&year<=1994;
replace periods=3 if  year>=1995&year<=1999;
replace periods=4 if  year>=2000&year<=2004;
replace periods=5 if  year>=2005&year<=2008;

tab year periods, m ;

label define periods 1 "1984-1989"
					2 "1990-1994"
					3 "1995-1999"
					4 "2000-2004"
					5 "2005-2008";

label values periods periods;
# d cr ;
